function GetMainDialog(fname, width, height) {
	var buttons = {
	        "log-in": {
	            text: "სისტემაში შესვლა",
	            id: "log-in",
	            click: function () {	            	
	            	$(".type").show();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=get_workers&status=1",
					    dataType: "json",
				        success: function(data) {
		                    if (data.error != "") {
		                        alert(data.error);
		                    }else {
		                    	$("input").blur();
		                    	$("#enter-dialog").html("<span class=\"ui-button-text\">შესვლა</span>");
		                    	$("#results_list").html(data.page);
		                    	$("#work_type").html(data.page1);
		                    	
		                    	$("#login-form").dialog("open");
		                    	$("#hidden_action").val(1);                	
		                    }
					    }
				    });		            		            		            						            
	            }
	        },
	        "log-out": {
	            text: "სისტემიდან გასვლა",
	            id: "log-out",
	            click: function () {
	            	$(".type").hide();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=get_workers&status=2",
					    dataType: "json",
				        success: function(data) {
		                    if (data.error != "") {
		                        alert(data.error);
		                    }else{
		                    	$("input").blur();
		                    	$("#enter-dialog").html("<span class=\"ui-button-text\">გასვლა</span>");
		                    	$("#results_list").html(data.page);
		                    	$("#login-form").dialog("open");
		                    	$("#hidden_action").val(2);
		                    }
					    }
				    });
	            }
	        },	
	        "go-timeout": {
	            text: "შესვენებაზე გასვლა",
	            id: "go-timeout",
	            click: function () {
	            	$(".type").hide();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=get_workers&status=3",
					    dataType: "json",
				        success: function(data) {
		                    if (data.error != "") {
		                        alert(data.error);
		                    }else {
		                    	$("input").blur();
		                    	$("#enter-dialog").html("<span class=\"ui-button-text\">შესვლა</span>");
		                    	$("#results_list").html(data.page);
		                    	$("#login-form").dialog("open");
		                    	$("#hidden_action").val(3);
		                    }
					    }
				    });		            		            		            						            
	            }
	        },	        
	           "back-timeout": {
	            text: "შესვენებიდან დაბრუნება",
	            id: "back-timeout",
	            click: function () {
	            	$(".type").hide();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=get_workers&status=4",
					    dataType: "json",
				        success: function(data) {
		                    if (data.error != "") {
		                        alert(data.error);
		                    }else {
		                    	$("input").blur();
		                    	$("#enter-dialog").html("<span class=\"ui-button-text\">შესვლა</span>");
		                    	$("#results_list").html(data.page);
		                    	$("#login-form").dialog("open");
		                    	$("#hidden_action").val(4);
		                    }
					    }
				    });		            		            		            						            
	            }
	        },
	        "typa-change": {
	            text: "სამუშაოს შეცვლა",
	            id: "work-change",
	            click: function () {	            	
	            	$(".type").show();
				    $.ajax({
				        url: aJaxURL,
					    data: "act=get_workers&status=5",
					    dataType: "json",
				        success: function(data) {
		                    if (data.error != "") {
		                        alert(data.error);
		                    }else {
		                    	$("input").blur();
		                    	$("#enter-dialog").html("<span class=\"ui-button-text\">სამუშაოს შეცვლა</span>");
		                    	$("#results_list").html(data.page);
		                    	$("#work_type").html(data.page1);		                    	
		                    	$("#login-form").dialog("open");
		                    	$("#hidden_action").val(1);                	
		                    }
					    }
				    });		            		            		            						            
	            }
	        }
	    };
    
    $("#" + fname).dialog({
    	position: "center",
        resizable: false,
        closeOnEscape: false,
        width: width,
        height: height,
        modal: true,
        stack: false,
        dialogClass: fname + "-class",
        buttons: buttons,
        open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();}
    });
}

function GetLOgDialog(fname, width, height) {
	var buttons = {
	        "enter": {
	            text: "შესვლა",
	            id: "enter-dialog",
	            click: function () {	        		
	    	    	param = new Object();   	    	
	                //Action	                
	                param.act		= 'log-in';
	                param.user		= $("#user").val();
	                param.worc_type	= $("#worc_type").val();
	                param.password	= $("#password").val();
	                param.action    = $("#hidden_action").val();
	                		                			            
				    $.ajax({
				        url: aJaxURL,
					    data: param,
					    dataType: "json",
				        success: function(data) {
		                    if ( data.answ == false ) {
		                        alert("პაროლი არასწორია");
		                        $("#password").val("");
		                    }else {
		                    	getWorkerTable();		                    	
		                    	$("#login-form").dialog("close");
		                        $("#user").val("");
		                        $("#password").val("");
		                    }
					    }
				    });	            						            							            
	            }
	        },
	        "cancel": {
	            text: "დახურვა",
	            id: "cancel-dialog",
	            click: function () {
	            	$(".results").css({'display':'none', 'zoom':'1'});
	            	$(this).dialog("close");
                    $("#user").val("");
	            }
	        }
	};	
    
    $("#" + fname).dialog({
    	autoOpen: false,
    	position: "center",
        resizable: false,
        closeOnEscape: false,
        width: width,
        height: height,
        modal: true,
        stack: false,
        dialogClass: fname + "-class",
        buttons: buttons,
        open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();}
    });
}

function GetDateTime(format) {
	var currentdate = new Date();
	var datetime;
	
	var d		= currentdate.getDate();
	var m		= currentdate.getMonth() + 1;
	var yy		= currentdate.getYear();
	
	var day		= (d < 10) ? '0' + d : d;
	var month	= (m < 10) ? '0' + m : m;
	var year	= (yy < 1000) ? yy + 1900 : yy;

	var h		= currentdate.getHours();
	var mm		= currentdate.getMinutes();
	var s		= currentdate.getSeconds();
	
	var hours	= (h < 10) ? '0' + h : h;
	var minutes = (mm < 10) ? '0' + mm : mm;
	var seconds = (s < 10) ? '0' + s : s;
	
	switch (format) {
		case 0:
			datetime = year + "-" + month  + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
			break;
		case 1:
			datetime = year + "-" + month  + "-" + day + "-" + hours + "-" + minutes + "-" + seconds;
			break;
		default:
			datetime = "Null";
	}
	
    return datetime;
}

function getPartTable(){
	var table	= "part_list";
	var aJaxURL = "worker.action.php";
	
	param = new Object();
	param.act	= "get_part_list";
	
    $.ajax({
        url: aJaxURL,
	    data: param,
	    dataType: "json",
        success: function(data) {
            if (data.error != "") {
            	alert(data.error);
            }else{
            	$("#"+table+"_tbody").html(data.page);
            }
	    }
    });
}

function getWorkerTable(){
	var table	="worker_list";
	var aJaxURL ="worker.action.php";	
	param = new Object();
	param.act	= "get_worker_list";
	
    $.ajax({
        url: aJaxURL,
	    data: param,
	    dataType: "json",
        success: function(data) {
            if (data.error != "") {
            	alert(data.error);
            }else{
            	$("#"+table+"_tbody").html(data.page);
            }
	    }
    });	
}

function getInfoTable(){
	var table	="info_list";
	var aJaxURL ="worker.action.php";	
	param = new Object();
	param.act	= "get_info_list";
	param.barcode = $("#active_catridgeBacode").val();
	
    $.ajax({
        url: aJaxURL,
	    data: param,
	    dataType: "json",
        success: function(data) {
            if (data.error != "") {
            	alert(data.error);
            	$("#"+table+"_tbody").html(data.page);
            }else{
            	$("#"+table+"_tbody").html(data.page);
            	getHistoryTable();
            }
	    }
    });		
}

function getHistoryTable(){
	var table	="history_list";
	var aJaxURL ="worker.action.php";
	param = new Object();
	param.act	  = "get_history_list";
	param.barcode = $("#active_catridgeBacode").val();
	
    $.ajax({
        url: aJaxURL,
	    data: param,
	    dataType: "json",
        success: function(data) {
            if (data.error != "") {
            	alert(data.error);
            	$("#"+table+"_tbody").html(data.page);
            }else{
            	$("#"+table+"_tbody").html(data.page);
            }
	    }
    });		
}
function SavePart(){
	var aJaxURL ="worker.action.php";	
	var act			= "save_part";
	var barcode     = $("#active_catridgeBacode").val();
	var cartridgeID	= $("#cartridgeID").val();
	var person		= $("#active").val();
	var wareHouseID	= $("#warehouseID").val();
	
    var data = $(".regular-checkbox:checked").map(function () { //Get Checked checkbox array
        return this.value;
    }).get();
    
    var parts = [];
    
    for (var i = 0; i < data.length; i++) {
    	parts.push(data[i]);        
    }
    param = new Object();	    	
    //Action
	param.act	      = act;
	param.barcode	  = barcode;
    param.list		  = parts;
    param.cartridgeID = cartridgeID; 
    param.person	  = person;
    param.wareHouseID = wareHouseID;
    
    var link	=  GetAjaxData(param);
    
    $.ajax({
        url: aJaxURL,
	    data: link,
	    dataType: "json",
        success: function(data) {
            if (data.error != "") {
            	GetNotify(data.error);
            }
	    }
    });	
}

function GetAjaxData(data) {
    param = "";
    for (var key in data) {
        var value = data[key];
        if (typeof (value) != "undefined") {
            param += key + "=" + value + "&"
        }
    }

    return param;
}

function GetNotify1(message){
	jNotify(message,
			{
			  autoHide : true,
			  clickOverlay : false,
			  MinWidth : 250,
			  TimeShown : 600,
			  ShowTimeEffect : 100,
			  HideTimeEffect : 100,
			  LongTrip :20,
			  HorizontalPosition : 'right',
			  VerticalPosition : 'bottom',
			  ShowOverlay : true,
	   		  ColorOverlay : '#000',
			  OpacityOverlay : 0.3,
			  onClosed : function(){
					$("#barcode_input").focus();
			  },
			  onCompleted : function(){
					$("#barcode_input").focus();
			  }
			});
}

function GetNotify(message){
	jNotify(message,
			{
			  autoHide : true,
			  clickOverlay : false,
			  MinWidth : 250,
			  TimeShown : 800,
			  ShowTimeEffect : 150,
			  HideTimeEffect : 150,
			  LongTrip :20,
			  HorizontalPosition : 'right',
			  VerticalPosition : 'bottom',
			  ShowOverlay : true,
	   		  ColorOverlay : '#000',
			  OpacityOverlay : 0.3,
			  onClosed : function(){
				  
			  },
			  onCompleted : function(){
				  
			  }
			});
}